
#pragma once

#include"PaleGem.h"
#include<xnamath.h>
#include<d3dcompiler.h>
#include"pgVertexShader.h"
#include"pgPixelShader.h"
#include"pgCamera.h"
#include<map>
#include"pgRenderableObject.h"


#define g_PG_pRenderer g_PG_pPaleGemFramework->GetRenderer()

struct ConstantBuffer
{
	pgMat44 mWorld;
	pgMat44 mView;
	pgMat44 mProjection;
};

/* 
pgRenderer
Basic class for DirectX 11 renderer
*/
class PALEGEM_API pgRender : public IEventListener
{
	public:

	pgRender();
	~pgRender();
	
	// Initializes DirectX
	HRESULT Init();					
	HRESULT Release();				//Cleans up all memory used by DirectX itself
	void	Render();				//Renders a scene


	ID3D11Device			*m_pd3dDevice;			// D3D11 device
	ID3D11DeviceContext		*m_pImmediateContext;	// Device Context
	ID3D11RenderTargetView	*m_pRenderTargetView;	// Target view
	ID3D11RasterizerState	*m_pRasterState;
	
	void OnEvent(IEvent *eEvent);
	bool IsInitialized(){return m_bIsInitialized;}

	pgVertexShader GetVertexShader(unsigned int idx) {return m_apVertexShaders[idx];}
	pgPixelShader GetPixelShader(unsigned int idx) {return m_apPixelShaders[idx];}
	pgCamera *GetViewCamera() {return m_pViewCamera;}
	void	SetViewCamera(pgCamera *pCam) {m_pViewCamera = pCam;}

	unsigned int GetIndexOfPixelShader(const char* szName);
	unsigned int GetIndexOfVertexShader(const char* szName);

	void AddRenderNode(IRenderableObject *pNode);

private:
	//DirectX init vars
	IDXGISwapChain			*m_pSwapChain;			// BackBuffer swapchain
	
	D3D_DRIVER_TYPE			m_driverType;			// Hardware, Software or Reference driver
	D3D_FEATURE_LEVEL		m_featureLevel;			// DX 9.1 - 11.0
	bool m_bIsInitialized;

	bool InitShaders();
	void ReleaseShaders();

	

	pgVertexShader *m_apVertexShaders;
	pgPixelShader *m_apPixelShaders;

	std::map<const char*, unsigned int> *m_pVertexMap;
	std::map<const char*, unsigned int> *m_pPixelMap;
	std::pair<const char*,unsigned int> m_charIntPair;
	int m_nPixelShaderCount;
	int m_nVertexShaderCount;

	std::list<IRenderableObject*> m_renderNodes;

	pgCamera *m_pViewCamera;


};
